<template>
  <div class="site-wrapper site-page--login">
      <div class="">
        <div class="site-content">
          <div class="brand-info">
            <h2 class="brand-info__text">楚天制药管理后台</h2>
          </div>
        <div class="login-main">
        <img class="page-login--logo" src="../image/logo@2x.png">
          <h3 class="login-title">管理员登录</h3>
          <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" status-icon>
            <el-form-item prop="userName">
              <el-input v-model="dataForm.userName" placeholder="帐号"></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input v-model="dataForm.password" type="password" placeholder="密码"></el-input>
            </el-form-item>
            <!--<el-form-item prop="captcha">-->
              <!--<el-row :gutter="20">-->
                <!--<el-col :span="14">-->
                  <!--<el-input v-model="dataForm.captcha" placeholder="验证码">-->
                  <!--</el-input>-->
                <!--</el-col>-->
                <!--<el-col :span="10" class="login-captcha">-->
                  <!--<img :src="captchaPath" @click="getCaptcha()" alt="">-->
                <!--</el-col>-->
              <!--</el-row>-->
            <!--</el-form-item>-->
            <el-form-item>
              <el-button class="login-btn-submit" type="primary" @click="dataFormSubmit()">登录</el-button>
            </el-form-item>
          </el-form>
        </div>
  </div>        </div>
  <div class="copyright">
  		<div>© 2019 Copyright zhiyao.118.easysoft168.com All Rights Reserved</div>
  		<div style="padding-top: 5px">技术支持：杭州东鸿科技有限公司</div>
  	</div>
          </div>
</template>

<script>
  import { getUUID } from '@/utils'
  export default {
    data () {
      return {
        dataForm: {
          userName: '',
          password: '',
          uuid: '',
          captcha: ''
        },
        dataRule: {
          userName: [
            { required: true, message: '帐号不能为空', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '密码不能为空', trigger: 'blur' }
          ]
        },
        captchaPath: ''
      }
    },
    created () {
      // this.getCaptcha()
    },
    methods: {
      // 提交表单
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl('/sys/login'),
              method: 'post',
              data: this.$http.adornData({
                'username': this.dataForm.userName,
                'password': this.dataForm.password,
                'uuid': this.dataForm.uuid
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$cookie.set('token', data.token)
                this.$router.replace({ name: 'home' })
              } else {
                this.getCaptcha()
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      // 获取验证码
      getCaptcha () {
        this.dataForm.uuid = getUUID()
        this.captchaPath = this.$http.adornUrl(`/captcha.jpg?uuid=${this.dataForm.uuid}`)
      }
    }
  }
</script>

<style lang="scss">
  .site-wrapper.site-page--login {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: rgba(38, 50, 56, .6);
    overflow: hidden;
    &:before {
      position: fixed;
      top: 0;
      left: 0;
      z-index: -1;
      width: 100%;
      height: 100%;
      content: "";
      background-image: url(~@/assets/img/login_bg.jpg);
      background-size: cover;
    }
    .site-content__wrapper {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      padding: 0;
      margin: 0;
      overflow-x: hidden;
      overflow-y: auto;
      background-color: transparent;
    }
    .site-content {
      position: absolute;
      top: 30%;
      left: 50%;
      margin: -175px 0 0 -250px;
      width: 500px;
      height: 350px;
    }
    .brand-info {
      margin: 10px 10px 10px 10px;
      color: #fff;
    }
    .brand-info__text {
      margin:  0 0 22px 0;
      font-size: 48px;
      font-weight: 400;
      text-transform : uppercase;
    }
    .brand-info__intro {
      margin: 10px 0;
      font-size: 16px;
      line-height: 1.58;
      opacity: .6;
    }
    .login-main {
      // position: absolute;
      top: 50%;
      right: 50%;
      padding: 49px 53px 39px;
      width: 470px;
      min-height: 100%;
      background-color: #fff;
    }
    .copyright {
        position: absolute;
        bottom: 0;
        padding: 15px 0;
        left: 50%;
        margin-left: -350px;
        width: 700px;
        text-align: center;
        color: #fff;
    }
    .login-title {
      font-size: 16px;
    }
    .login-captcha {
      overflow: hidden;
      > img {
        width: 100%;
        cursor: pointer;
      }
    }
    .login-btn-submit {
      width: 100%;
      margin-top: 38px;
    }
    // main
    .page-login--logo {
      width: 290px;
      margin-bottom: 2em;
      margin-top: -2em;
    }
      // 登录表单
      .page-login--form {
        width: 290px;
        // 卡片
        .el-card {
          margin-bottom: 15px;
        }
        // 登录按钮
        .button-login {
          width: 100%;
        }
        // 输入框左边的图表区域缩窄
        .el-input-group__prepend {
          padding: 0px 14px;
        }
        .login-captcha {
          background-image: linear-gradient(90deg, #C7C7C7 0%, #F9F9F9 100%);
          height: 40px - 2px;
          width: 126px;
          background-size: cover;
          background-position: center;
          margin: 0px -20px;
          border-top-right-radius: 2px;
          border-bottom-right-radius: 2px;
        }
        // 登陆选项
        .page-login--options {
          margin: 0px;
          padding: 0px;
          font-size: 14px;
          margin-bottom: 15px;
          font-weight: bold;
        }
      }
  }
</style>
